<template>
<h1>循环指令</h1>
  <ul>
    <li v-for="item in 3">item:{{item}}</li>
  </ul>
  <ul>
    <li v-for="item in productArr">item:{{item}}</li>
  </ul>
  <ul>
    <li v-for="item in productArr.length">item:{{productArr[item]}}</li>
  </ul>
  <hr>

  <table border="1">
    <tr>
      <th>序号</th>
      <th>商品名称</th>
      <th>商品价格</th>
      <th>商品数量</th>
    </tr>
    <tr v-for="(item,index) in productArr">
      <td>{{index+1}}</td>
      <td>{{item.title}}</td>
      <td>{{item.price}}</td>
      <td>{{item.num}}</td>
      <td><button @click="del(index)">删除</button></td>
    </tr>
  </table>
</template>


<script setup>
import {ref} from "vue";

let productArr = ref([
    {title:'手机',price:1000,num:1000},
    {title:'电脑',price:2000,num:2000},
    {title:'鼠标',price:3000,num:3000},
    {title:'键盘',price:4000,num:4000},
    {title:'键盘',price:4000,num:4000},
    {title:'键盘',price:4000,num:4000},
    {title:'键盘',price:4000,num:4000},
    {title:'键盘',price:4000,num:4000},
    {title:'耳机',price:5000,num:5000}
]);

const del = (index) => {
    productArr.value.splice(index,1);
}

</script>


<style scoped>

</style>